package cn.bdqn.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;

import Entity.User;

public class GuolvFilter implements Filter {


	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1,
			FilterChain arg2) throws IOException, ServletException {
		HttpServletRequest req=(HttpServletRequest) arg0;

		HttpServletResponse resp=(HttpServletResponse) arg1;
		Myreq re=new Myreq(req);
//		String parameter = req.getParameter("username");
//		req.removeAttribute(z);("USER_NAME", parameter);
		User user = (User) req.getAttribute("NAME");
		re.replayname(user.getName());
		System.out.println("22"+re.getAttribute("NAME")+"11");
		arg2.doFilter(re, resp);
	}
	

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}
	
	class Myreq extends HttpServletRequestWrapper{

		public Myreq(HttpServletRequest request) {
			super(request);
			// TODO Auto-generated constructor stub
		}
		
		public String replayname(String name) {
			name=name.trim();
			return name;
				
		}
		@Override
		public String getParameter(String name) {
			String username = super.getParameter(name);
			if (username == null) {
				return null;
				
			}
			
			return replayname(username);
		}
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	
}

